﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using WoTStats.Web.Models;
using Newtonsoft.Json.Linq;
using WoTStats.Model;

namespace WoTStats.Web.Controllers
{
    public class BattleResultsUploadController : Controller
    {
        [HttpPost]
        public static string UploadBattleResults(BattleResultsPOSTData battleResultsJson)
        {
            string battleResults = battleResultsJson.Data;

            if (string.IsNullOrEmpty(battleResults))
            {
                //Error: Results file is null or empty."
                return "1";
            }
            else
            {
                try
                {
                    JObject fullResults = JObject.Parse(battleResults);
                    JObject common = (JObject)fullResults["common"];
                    JObject personal = (JObject)fullResults["personal"];
                    JObject players = (JObject)fullResults["players"];
                    JObject vehicles = (JObject)fullResults["vehicles"];


                    return (string)common["arenaTypeName"];
                }
                catch (Exception e)
                {
                    return e.Message;
                }
            }

            return "0"; ///complete
        }

    }
}
